Skip to content

feat(memory): index OpenCode sessions (opencode harness) - #115

Merged
sandstream merged 2 commits into
mainfrom
feat/memory-opencode-parser
Jun 27, 2026
Merged

sandstream merged 2 commits into
mainfrom
feat/memory-opencode-parser

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Adds the missing OpenCode transcript parser so kit memory index / indexAllHarnesses covers OpenCode alongside the existing 7 harnesses (claude-code, codex, gemini, continue, cursor, amazon-q, cline). Closes the memory half of the OpenCode-parity gap.

How OpenCode stores sessions

Flat JSON under $OPENCODE_DATA_DIR (default ~/.local/share/opencode) in a storage/ tree, with the message text split into separate part files:

  • storage/session/<projectHash>/<sessionID>.json — session info (id, directory)
  • storage/message/<sessionID>/msg_<id>.json — per message (role, time)
  • storage/part/.../prt_<id>.json — content parts (type:"text", text)

Parser

  • reads sessions → sessionID → project/cwd
  • reads messages → role (user|assistant) + timestamp (tolerates time.created and time_created)
  • globs all part files and groups text parts by their messageID field — so it does not depend on the exact part-dir nesting (which has varied across versions)
  • inserts each message with a stable uuid opencode:<session>:<message> → INSERT OR IGNORE makes re-runs idempotent

Verified against sst/opencode's message-v2 schema (role values; text part = {type:"text", text}).

Honest caveats

  • Defensive + strict: anything not matching the documented shape is skipped, so on a layout it doesn't recognize (e.g. newer SQLite-backed installs) it indexes nothing rather than garbage — a safe no-op, not a regression.
  • The SQLite-backed layout is a separate follow-up.
  • Not yet verified against a live OpenCode install (no sample on hand) — fixture-tested against the documented flat-JSON format. Worth a smoke-test against a real ~/.local/share/opencode before relying on it.

Tests: text-part join (excludes tool/ignored/empty parts), idempotent re-run, absent-dir no-op. Full suite 1538/0. Independent of #109.


🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

Adds the missing OpenCode transcript parser so `kit memory index` (and
indexAllHarnesses) covers OpenCode alongside claude-code/codex/gemini/
continue/cursor/amazon-q/cline.

OpenCode persists sessions as flat JSON under $OPENCODE_DATA_DIR
(default ~/.local/share/opencode) in a storage/ tree, with the message
TEXT split into separate `part` files. The parser:
- reads storage/session/** for sessionID → project/cwd,
- reads storage/message/** for role (user|assistant) + timestamp,
- globs storage/part/** and groups text parts by their `messageID` field
  (so it doesn't depend on the exact part-dir nesting, which has varied),
- inserts each message with a stable uuid opencode:<session>:<message>
  (INSERT OR IGNORE → idempotent re-runs).

Verified against sst/opencode's message-v2 schema (role values; text part
= {type:"text", text}; time.created / time_created tolerated). Defensive +
strict: unrecognized shapes are skipped, so on a layout it doesn't know
(e.g. newer SQLite-backed installs) it indexes nothing rather than garbage
— a safe no-op, not a regression. The SQLite-backed layout is a separate
follow-up. Not yet verified against a live install (no sample on hand);
fixture-tested against the documented flat-JSON format.

Tests: text-part join (excludes tool/ignored/empty parts), idempotent
re-run, absent-dir no-op. Full suite 1538/0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@sandstream
sandstream force-pushed the feat/memory-opencode-parser branch from 4f6c704 to 52ceaa8 Compare June 27, 2026 11:05
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

The rebase onto 2.1.1 brought a stricter prettier config; format:check
flagged the two new opencode files. Format-only, no logic change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit c724b22 into main Jun 27, 2026
16 checks passed
@sandstream
sandstream deleted the feat/memory-opencode-parser branch June 30, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants